//
// some timing tests for floating-point arithmetic
//
// for 1000 passes * 40 coefficients, time is 847 msec,
// for about 21 usec per term.  note the series is unsigned int.
//

const unsigned int passes = 1000;
const unsigned int vlength = 40;
double coeff[vlength];
unsigned int series[vlength];

void setup() {
    Serial.begin(9600);
    Serial.flush();
}

void loop() {
    unsigned long tstart;
    unsigned long telapse;
    double accum;
    unsigned int i;
    unsigned int j;
    unsigned int l;
    unsigned int z;
    for(i = 0; i < vlength; i++) {
        coeff[i] = (1.0 * i) / (vlength * (vlength - 1.0));
        series[i] = i + 3;
    }

    for(l = 0; l < 10; l++) {
        tstart = millis();
        accum = 0.0;
        for(j = 0; j < passes; j++)
            for(i = 0; i < vlength; i++)
                accum += coeff[i] * series[i];
        telapse = millis() - tstart;
        z = (unsigned int)(accum);
        Serial.print(z);
        Serial.print("  ");
        Serial.print(telapse, DEC);
        Serial.println();
        Serial.flush();
    }
    for(;;)
        ;
}
